package com.qf.dao.impl;

import com.qf.dao.IUserDao;
import com.qf.entity.User;
import com.qf.framwork.base.BaseDao;

import java.util.List;

/**
 * @author zewei
 * @create_time 2023/2/23
 */
public class UserImpl extends BaseDao<User>implements IUserDao {

    @Override
    public int delete(Integer id) {
        String sql="delete from user where id =?";
        return super.update(sql,id);
    }

    @Override
    public int update(User user) {
        String sql = "update user set username = ?, password = ?, nickname = ?, update_time = now() where id = ?";
        return super.update(sql,user.getUsername(),
                user.getPassword(),
                user.getNickname(),
                user.getId());
    }

    @Override
    public User queryOne(Integer id) {

        String sql = "select * from user where id = ?";
        return super.queryOne(sql,User.class,id);
    }

    @Override
    public List<User> queryList() {

        String sql = "select * from user";
        return super.queryList(sql, User.class);
    }

    @Override
    public int insert(User user) {

        String sql = "insert into user values(null, ?, ?, ?, ?, null, ?, ?, 0, now(), now(), 0, 0)";
        return super.insert(sql,user.getUsername(),
                user.getPassword(),
                user.getNickname(),
                user.getSex(),
                user.getEmail(),
                user.getPhone());
    }
}
